# CMake lowest version requirement
cmake_minimum_required(VERSION 3.14)

# 设置工程名
project(OP_EXAMPLE)

# Compile options
add_compile_options(-std=c++17)
if(DEFINED ENV{CXX_ABI})
    add_definitions(-D_GLIBCXX_USE_CXX11_ABI=$ENV{CXX_ABI})
else()
    add_definitions(-D_GLIBCXX_USE_CXX11_ABI=0)
endif()

# 设置编译选项
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY  "../../out") 
set(CMAKE_CXX_FLAGS_DEBUG "-fPIC -O0 -g -Wall")
set(CMAKE_CXX_FLAGS_RELEASE "-fPIC -O2 -Wall")

# 设置可执行文件名（如opapi_test），并指定待运行算子文件*.cpp所在目录
add_executable(main
               main.cpp) 

# 设置ASCEND_PATH（CANN包目录）和INCLUDE_BASE_DIR（头文件目录）
if(NOT "$ENV{ASCEND_CUSTOM_PATH}" STREQUAL "")      
    set(ASCEND_PATH $ENV{ASCEND_CUSTOM_PATH})
else()
    set(ASCEND_PATH $ENV{ASCEND_HOME_PATH}/aarch64-linux)
endif()
set(ATB_PATH $ENV{ATB_HOME_PATH})
set(INCLUDE_BASE_DIR "${ASCEND_PATH}/include")
set(LIB_BASE_DIR "/usr/local/lib64/")
include_directories(
    ${INCLUDE_BASE_DIR}
    ${INCLUDE_BASE_DIR}/aclnn
    ${ATB_PATH}/include
    ${CMAKE_CURRENT_SOURCE_DIR}
)

target_link_libraries(main PRIVATE
                      ${ASCEND_PATH}/lib64/libmsprofiler.so
                      ${ASCEND_PATH}/lib64/libascendcl.so
                      ${ASCEND_PATH}/lib64/libnnopbase.so
                      ${ASCEND_PATH}/lib64/libopapi.so
                      ${ATB_PATH}/lib/liblcal.so
                      ${ATB_PATH}/lib/libatb.so
                      ${ATB_PATH}/lib/libasdops.so
                      ${CMAKE_SOURCE_DIR}/../../../examples/atb_plugin/out/libascendc_kernels.so
                      ${CMAKE_SOURCE_DIR}/../../../examples/atb_plugin/out/libplugin_aclnn_op.so
                      ${CMAKE_SOURCE_DIR}/../../../examples/atb_plugin/out/libplugin_custom_op.so
                      )
                      
# 可执行文件在CMakeLists文件所在目录的bin目录下
install(TARGETS main DESTINATION ${CMAKE_RUNTIME_OUTPUT_DIRECTORY})